/**
 * 多人副本
 * 逻辑代码
 */
exports.do_drfb = function () {
    var foo = require('./foo.js');
    var drfb_flag = true;
    var k = 0; //副本计数
    var gsdd = 0;
    if (ui.ytl.isChecked()) {
        function c_drfb() {
            console.log(foo.p_dwxx());
            if (ui.syyb.isChecked() || k >= 1) {
                foo.p_hd_f();
                foo.clk(foo.p_bzrw);
                foo.clk(foo.p_drfb, 5, 0, 'wtf', c_drfb, y_cjdrfb);
            } else {
                foo.is_dz(() => {
                    foo.p_hd_f();
                    foo.clk(foo.p_bzrw);
                    foo.clk(foo.p_drfb, 5, 0, 'wtf', c_drfb, y_cjdrfb);
                });
            }
        }
        function y_cjdrfb() {
            foo.clk(foo.text_drfb, 8, 0, 'wtf', c_drfb, () => {
                foo.clk(
                    foo.p_cjdrfb,
                    8,
                    0,
                    'wtf',
                    () => {
                        drfb_flag = false;
                    },
                    y_jrfb
                );
            });
        }
        function y_jrfb() {
            if (foo.clk(foo.p_qd, 2, 0, 'wtf') || foo.clk(foo.p_cjdw, 2, 0, 'wtf')) {
                //qd:创建队伍时目前无相同目标队伍。cjdw:创建队伍时目前有相同目标队伍
                sleep(5000);
                foo.clk(foo.p_gb, 2000);
                sleep(310 * 1000);
                foo.clk(foo.p_qd, 60, 0, 'wtf');
            } //是否需要创建队伍
            foo.clk(foo.p_ljqw, 2, 0, 'wtf'); //队伍不满
            foo.clk(foo.p_jrfb, 60, 0, 'wtf', c_drfb, y_drfb);
        }
        function y_drfb() {
            function n_bd() {
                sleep(5000);
                foo.clk(foo.p_zdzz, Number(storage.get('configure').outTime_drfb) - 60, 0, 'wtf', null, '0');
            }
            foo.zjmzx(() => {
                foo.clk(foo.p_gb, 10, 0, 'wtf', null, 5);
            });
            foo.clk(foo.p_zdzz, Number(storage.get('configure').outTime_drfb) - 60, 0, 'wtf', null, n_bd);
            foo.clk(foo.p_djsy, null, 2);
            console.log('本轮第' + k + '个副本结束');
            k++;
        }
        function jhll() {
            function lxgj() {
                foo.clk(foo.p_rwbq);
                foo.clk(foo.p_hdbq, 2, 0, 'wtf', lxgj, () => {
                    foo.clk(foo.p_hdbq);
                    foo.clk(foo.p_lxgj, 2, 0, 'wtf', lxgj, () => {
                        foo.clk(foo.p_qd, 2, 0, 'wtf', lxgj);
                    });
                });
            }
            function zhao_jhll() {
                foo.clk(foo.p_hd);
                foo.clk(foo.p_bzrw);
                foo.clk(foo.p_jhll, 2, 0, 'wtf', zhao_jhll);
            }
            zhao_jhll();
            sleep(1000);
            if (ui.ytl_jsh.getSelectedItemPosition() == 0 || ui.ytl_jsh.getSelectedItemPosition() == 1) {
                function dggj() {
                    foo.clk(foo.p_dg5c, 2, 0, 'wtf', jhll, () => {
                        foo.clk(foo.p_qd, 10, 0, 'wtf', dggj);
                        sleep(2000);
                        foo.clk(foo.p_qd, 5, 0, 'wtf');
                    });
                }
                dggj();
            } else if (ui.ytl_jsh.getSelectedItemPosition() == 2 || ui.ytl_jsh.getSelectedItemPosition() == 3) {
                function gmgj() {
                    foo.clk(foo.p_gm5c, 2, 0, 'wtf', jhll, () => {
                        foo.clk(foo.p_qd, 10, 0, 'wtf', dggj);
                        sleep(2000);
                        foo.clk(foo.p_qd, 5, 0, 'wtf');
                    });
                }
                gmgj();
            }
            if (ui.ytl_jsh.getSelectedItemPosition() == 1 || ui.ytl_jsh.getSelectedItemPosition() == 3) {
                sleep(5 * 60000);
                lxgj();
            }
        }
        function hly() {
            foo.clk(foo.p_djxdt, 5, 0, 'wtf', null, 2);
            foo.clk(foo.p_dkxdt, 5, 0, 'wtf');
            foo.clk(foo.p_sjdt, 5, 0, 'wtf');
            foo.clk(foo.p_ly, 5, 0, 'wtf', null, 2);
            foo.clk(foo.p_csdbz, 5, 0, 'wtf', null, 9);
        }

        while (drfb_flag) {
            foo.zjmzx(c_drfb);
        }
        switch (ui.ytl_jsh.getSelectedItemPosition()) {
            case 0:
                foo.zjmzx(jhll);
                break;
            case 1:
                foo.zjmzx(jhll);
                break;

            case 2:
                foo.zjmzx(jhll);
                break;
            case 3:
                foo.zjmzx(jhll);
                break;
            case 4:
                foo.zjmzx(hly);
                break;
            default:
                null;
        }
    } else {
        console.log('没有选中任务');
    }
    foo.zjmzx(()=>{
        toastLog('多人副本结束了');
    });
    threads.currentThread().interrupt();
    delete variables.threads.a2;
    layout1.drfb.setText('开始执行');
};
